<html>
<head><meta charset="utf-8"><title>Dump the hir_ty level AST? · t-compiler/rust-analyzer · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/index.html">t-compiler/rust-analyzer</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Dump.20the.20hir_ty.20level.20AST.3F.html">Dump the hir_ty level AST?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="239013770"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Dump%20the%20hir_ty%20level%20AST%3F/near/239013770" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jade <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Dump.20the.20hir_ty.20level.20AST.3F.html#239013770">(May 16 2021 at 23:13)</a>:</h4>
<p>I'd like to debug <a href="https://github.com/rust-analyzer/rust-analyzer/issues/8747">https://github.com/rust-analyzer/rust-analyzer/issues/8747</a>, for which I'd like a dump of the hir_ty AST. Is there a currently existing way to get that information out?</p>



<a name="239014035"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Dump%20the%20hir_ty%20level%20AST%3F/near/239014035" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Dump.20the.20hir_ty.20level.20AST.3F.html#239014035">(May 16 2021 at 23:18)</a>:</h4>
<p>There's a "View HIR" command, but I doubt it outputs what you want</p>



<a name="239014328"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Dump%20the%20hir_ty%20level%20AST%3F/near/239014328" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Dump.20the.20hir_ty.20level.20AST.3F.html#239014328">(May 16 2021 at 23:24)</a>:</h4>
<p>Is the problem that <code>AttrDefId::FunctionId(f) =&gt; Some(f.lookup(self.db.upcast()).container.into()),</code> doesn't get you the containing trait?</p>



<a name="239014484"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Dump%20the%20hir_ty%20level%20AST%3F/near/239014484" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jade <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Dump.20the.20hir_ty.20level.20AST.3F.html#239014484">(May 16 2021 at 23:27)</a>:</h4>
<p>I think so, yes. I could put some logging into there again but that's my recollection. I believe the lowering is the problem because asking it to parse gets a reasonable concrete syntax tree</p>



<a name="239014993"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Dump%20the%20hir_ty%20level%20AST%3F/near/239014993" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Dump.20the.20hir_ty.20level.20AST.3F.html#239014993">(May 16 2021 at 23:36)</a>:</h4>
<p>I don't think we have any debugging facilities for that, so logging is probably your best bet</p>



<a name="239015037"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Dump%20the%20hir_ty%20level%20AST%3F/near/239015037" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jade <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Dump.20the.20hir_ty.20level.20AST.3F.html#239015037">(May 16 2021 at 23:37)</a>:</h4>
<p>i was thinking of adding one, so just wanted to make sure i wasn't missing something</p>



<a name="239713386"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Dump%20the%20hir_ty%20level%20AST%3F/near/239713386" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jade <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Dump.20the.20hir_ty.20level.20AST.3F.html#239713386">(May 21 2021 at 08:19)</a>:</h4>
<p>I figured this out by just reading source code. So what's going on is that the container is just being set to the module. This makes sense as the module is the only container that we really know about in nameres/collector.rs in ModCollector: there is no parent information attached to the functions that I can find and we can get AST references, but there is no way to dereference them (probably by design). So I need to change the input into there. I feel like this is going to be a difficult change.</p>



<a name="239722777"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Dump%20the%20hir_ty%20level%20AST%3F/near/239722777" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Dump.20the.20hir_ty.20level.20AST.3F.html#239722777">(May 21 2021 at 09:38)</a>:</h4>
<p>Hmm, do we set it to the block module or the "real" module? The collector should know about both</p>



<a name="239722890"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Dump%20the%20hir_ty%20level%20AST%3F/near/239722890" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Dump.20the.20hir_ty.20level.20AST.3F.html#239722890">(May 21 2021 at 09:39)</a>:</h4>
<p>There are some bugs with how we store inner items in the ItemTree though, maybe they cause issues here</p>



<a name="239739321"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Dump%20the%20hir_ty%20level%20AST%3F/near/239739321" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jade <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Dump.20the.20hir_ty.20level.20AST.3F.html#239739321">(May 21 2021 at 12:08)</a>:</h4>
<p>I believe that it's putting the trait functions into the block module of the containing function, rather than into the trait itself. I'm not sure if this is bad behaviour. Hopefully tomorrow I'll have a chance to compare this to a normal trait where we don't have this bug and see if it is doing something reasonable.</p>



<a name="239740149"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Dump%20the%20hir_ty%20level%20AST%3F/near/239740149" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Dump.20the.20hir_ty.20level.20AST.3F.html#239740149">(May 21 2021 at 12:15)</a>:</h4>
<p>might be related to this: <a href="https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/hir_def/src/body/tests/block.rs#L156-L157">https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/hir_def/src/body/tests/block.rs#L156-L157</a></p>



<a name="239779495"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Dump%20the%20hir_ty%20level%20AST%3F/near/239779495" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Dump.20the.20hir_ty.20level.20AST.3F.html#239779495">(May 21 2021 at 16:39)</a>:</h4>
<p>hmm, this seems weird, because we're definitely using the right <code>container</code> for trait functions here: <a href="https://github.com/rust-analyzer/rust-analyzer/blob/de403b10448e23f232804596538de92fc57203d6/crates/hir_def/src/data.rs#L156">https://github.com/rust-analyzer/rust-analyzer/blob/de403b10448e23f232804596538de92fc57203d6/crates/hir_def/src/data.rs#L156</a></p>



<a name="239781166"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Dump%20the%20hir_ty%20level%20AST%3F/near/239781166" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Dump.20the.20hir_ty.20level.20AST.3F.html#239781166">(May 21 2021 at 16:52)</a>:</h4>
<p><span class="user-mention silent" data-user-id="211727">Jonas Schievink  [he/him]</span> <a href="#narrow/stream/185405-t-compiler.2Frust-analyzer/topic/Dump.20the.20hir_ty.20level.20AST.3F/near/239722890">said</a>:</p>
<blockquote>
<p>There are some bugs with how we store inner items in the ItemTree though, maybe they cause issues here</p>
</blockquote>
<p>Wrote down some details about this in <a href="https://github.com/rust-analyzer/rust-analyzer/issues/8911">https://github.com/rust-analyzer/rust-analyzer/issues/8911</a></p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>